package com.example.LibrarySystem.Exception;

import com.example.LibrarySystem.response.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局异常处理
 */

@ControllerAdvice
public class MyExceptionHandler {
    @ExceptionHandler(ServiceException.class) // 处理对应的异常
    @ResponseBody
    public Result handle(ServiceException e){
        Result result = new Result();
        result.setStatus(-1);
        result.setMsg(e.getMessage());
        return result;
    }
}
